<!--
    团购管理页面
-->
<template>
  <div>
    <el-tabs type="border-card">
      <el-tab-pane label="查看线路">
        <el-table
            :data="lineInfo.slice((currentPage-1)*PageSize,currentPage*PageSize)"
            border
            style="width: 100%">
          <el-table-column
              type="index"
              label="序号"
              fixed
              width="150">
          </el-table-column>
          <el-table-column
              fixed prop="lineName" label="线路名称" width="150">
          </el-table-column>
          <el-table-column
              fixed prop="days" label="出游天数" width="150">
          </el-table-column>
          <el-table-column
              fixed prop="price" label="线路价格" width="150">
          </el-table-column>
          <el-table-column
              fixed prop="teamBuy" label="是否为团购线路" width="150">
          </el-table-column>
          <el-table-column
              fixed prop="typeName" label="线路类型" width="150">
          </el-table-column>
          <el-table-column
              fixed  label="操作" width="150">
            <template #default="scope">
              <el-button @click="PutBuy(scope.row)" type="text" size="small">设置团购</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-size="PageSize" layout="total, sizes, prev, pager, next, jumper"
            :total="lineInfo.length" s>
        </el-pagination>
      </el-tab-pane>
      <el-tab-pane label="查看团购">
        <el-table
            :data="teambuyLine.slice((currentPage-1)*PageSize,currentPage*PageSize)"
            border
            style="width: 100%">
          <el-table-column
              type="index"
              label="序号"
              fixed
              width="150">
          </el-table-column>
          <el-table-column
              fixed prop="lineName" label="线路名称" width="150">
          </el-table-column>
          <el-table-column
              fixed prop="days" label="出游天数" width="150">
          </el-table-column>
          <el-table-column
              fixed prop="price" label="线路价格" width="150">
          </el-table-column>
          <el-table-column
              fixed prop="teamBuyPrice" label="线路团购价格" width="150">
          </el-table-column>
          <el-table-column
              fixed prop="vehicle" label="出游工具" width="150">
          </el-table-column>
          <el-table-column
              fixed prop="teamBuy" label="操作" width="150">
          </el-table-column>
        </el-table>
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-size="PageSize" layout="total, sizes, prev, pager, next, jumper"
            :total="teambuyLine.length" s>
        </el-pagination>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
export default {
  name: "adminGroupbuyPage",
  data(){
    return{
      lineInfo:[],
      teambuyLine:[],
      // 默认显示第几页
      currentPage:1,
      // 默认每页显示的条数
      PageSize:10,
    }
  },
  created() {
        this.getGroupbuy(),
        this.getTeamBuy()
  },
  filters:{
    teamBuyP:function (val){
      return val;
    }
  },
  methods:{
    getGroupbuy:function(){
      this.$axios.get("/api/admin/groupbuy").then(res => {
        this.lineInfo=res.data
        for (let i=0;i<this.lineInfo.length;i++){
          if (res.data[i].teamBuy == 0){
            this.lineInfo[i].teamBuy ='非团购';
          }else if (res.data[i].teamBuy == 1){
            this.lineInfo[i].teamBuy ='团购';
            this.lineInfo[i].price = this.lineInfo[i].teamBuyPrice;
          }
        }
      })
    },
    getTeamBuy:function(){
      this.$axios.get("/api/admin/teamBuy").then(res => {
        this.teambuyLine=res.data
      })
    },
    PutBuy:function (val){
      console.log(val)
      this.$router.push({path:'/adminPutBuy',query:{lineInfo:val}})
    },
    // 分页
// 每页显示的条数
    handleSizeChange(val) {
      // 改变每页显示的条数
      this.PageSize = val
      // 在改变每页显示的条数时，要将页码显示到第一页
      this.currentPage = 1
    },
// 显示第几页
    handleCurrentChange(val) {
      // 改变默认的页数
      this.currentPage = val
    },
  },

}
</script>

<style scoped>

</style>